package com.cz.mes.view;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class SycColumn {
    public static void main(String[] args) {
        String fromDbGroup = "uat3";
        String toDbGroup = "mes-prod-master";

        try {
            Entity entity = Db.use(fromDbGroup).queryOne("select * from mes_vw_table where id = 15");
            entity.remove("id");
            long tableId = Db.use(toDbGroup).insertForGeneratedKey(entity);
            System.out.println(tableId);

            List<Entity> entities = Db.use(fromDbGroup).query("select * from mes_vw_column where table_id = 15");
            if(CollUtil.isNotEmpty(entities)){
                entities.forEach(vwColumn -> {
                    vwColumn.remove("id");
                    vwColumn.set("table_id",tableId);
                    vwColumn.set("create_on",new Date());
                });
                int[] result =Db.use(toDbGroup).insert(entities);
                System.out.println(result);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
